/*****************************************************************************
* Copyright (c) 2014,H.B.
* All rights reserved.
* 
* FileName : DtvBuffer.java
* Description : define DtvBuffer
* 
* Version : 0.0.0
* Author : HB   Reviewer : 
* Date : 2014-07-08
* Record : Create
*
* History : 
* (1) Version : 0.0.0
*     Author : HB   Reviewer : 
*     Date : 2014-07-08
*     Record : Create
****************************************************************************/

package hb.dtv;


public class DtvBuffer
{

	final int mJniPtr;

	DtvBuffer(int ptr)
	{
		mJniPtr=ptr;
	}

	public void Release()
	{
		nativeRelease(mJniPtr);
	}

	public void AssociateSignal(DtvSignal signal)
	{
		nativeAssociateSignal(mJniPtr,signal.mJniPtr);
	}

	public void DisassociateSignal( )
	{
		nativeDisassociateSignal(mJniPtr);
	}

	public int GetDataSize( )
	{
		return nativeGetDataSize(mJniPtr);
	}

	public byte[][] ReadData(int count)
	{
		return nativeReadData(mJniPtr,count);
	}

	public int ReadData(byte[][] data,int[] len)
	{
		return nativeReadData(mJniPtr,data,len);
	}

	@Override
	public boolean equals(Object o) 
	{
		 if (this == o) return true;
		 if (!(o instanceof DtvBuffer)) return false;
		 DtvBuffer d=(DtvBuffer)o;
		 if(mJniPtr==d.mJniPtr)return true;
		 return nativeGetHandle(mJniPtr)==nativeGetHandle(d.mJniPtr);
	}

	@Override
	protected void finalize() throws Throwable
	{
		nativeDestroy(mJniPtr);
		super.finalize();
	}

	private native static void nativeAssociateSignal(int jniPtr,int siganl);
	
	private native static void nativeDisassociateSignal(int jniPtr);
	
	private native static void  nativeClearAll(int jniPtr);
	
	private native static int nativeGetDataSize(int jniPtr);
	
	private native static byte[][] nativeReadData(int jniPtr,int count);
	
	private native static int nativeReadData(int jniPtr,byte[][] data,int[] len);
	
	private native static int nativeGetHandle(int jniPtr);
	
	private native static void nativeRelease(int jniPtr);
	
	private native static void nativeDestroy(int jniPtr);
}

